import { Entity, Column, Index, OneToMany } from 'typeorm';
import { BaseEntity } from '../../../common/entity/base.entity';
import { User } from '../../user/entities/user.entity';

@Entity('roles')
@Index(['code'], { unique: true })
export class Role extends BaseEntity {
  @Column({
    name: 'code',
    type: 'varchar',
    length: 50,
    comment: '角色代码',
  })
  code: string;

  @Column({
    name: 'name',
    type: 'varchar',
    length: 100,
    comment: '角色名称',
  })
  name: string;

  @Column({
    name: 'description',
    type: 'text',
    nullable: true,
    comment: '角色描述',
  })
  description?: string;

  @OneToMany(() => User, user => user.role)
  users: User[];
}
